<?php

use Sharks\Core\AppContext;
use Sharks\Core\Support\Base\Precondition;
use Sharks\Core\Support\Base\DefValue;
use Sharks\Core\Support\Base\Str;

/**
 * csrf的表达
 * @param $params
 * @param $smarty
 */
function smarty_function_form_csrf($params, &$smarty) {
    $csrfField = DefValue::pick($params, 'field', '_csrf');
    $randStr = Str::randStr(16);
    AppContext::instance()->flash()->put($csrfField, $randStr);
	
	echo "<input type='hidden' value='$randStr' name='$csrfField'>";
}